#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define VEC_SZ 20
#define STR_SZ 40

#define PEGAR_VETOR(F, I, V)                           \
  while ((c = fgetc(F)) != EOF) {                      \
    i = 1;                                             \
    if (I == VEC_SZ)                                   \
      break;                                           \
    else if (c == '\n')                                \
      continue;                                        \
    else {                                             \
      V[I][0] = c;                                     \
      while (((c = fgetc(F)) != '\n') && (c != EOF)) { \
        if (i == STR_SZ) break;                        \
        else V[I][i++] = c;                            \
      }                                                \
      V[I++][i] = '\0';                                \
    }                                                  \
  }

int main(int argc, char ** argv) {
  char gab[VEC_SZ][STR_SZ + 1];
  char tst[VEC_SZ][STR_SZ + 1];
  FILE * gabf;
  FILE * tstf;
  int gc, tc, i, c, btd;

  if (argc != 3) {
    fprintf(stderr, "Use: stat <arq_gabarito> <arq_teste>\n");
    exit(1);
  }

  if ((gabf = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Erro de leitura: %s\n", argv[1]);
    exit(1);
  }

  if ((tstf = fopen(argv[2], "r")) == NULL) {
    fprintf(stderr, "Erro de leitura: %s\n", argv[2]);
    (void) fclose(gabf);
    exit(1);
  }

  gc = tc = 0;
  PEGAR_VETOR(gabf, gc, gab);
  PEGAR_VETOR(tstf, tc, tst);

  fclose(gabf);
  fclose(tstf);

  btd = 0;
  for (--tc; tc >= 0; tc--)
    for (i = gc - 1; i >= 0; i--)
      if (!strcmp(tst[tc], gab[i])) btd++;

  printf("%.2f%%\n", (gc) ? (100.0 * btd / gc) : 0.0);

  return 0;
}

